"""
异常链（Exception Chaining）是指在处理一个异常时，又引发了新的异常，可以用 raise ... from ... 的语法将新的异常和原始异常串联起来。
"""

from pathlib import Path


def process_file(filename):

    try:
        with open(filename) as f:
            return f.read()
    except FileNotFoundError as e:
        raise RuntimeError("文件处理失败") from e


try:
    data = process_file("not_exist.txt")
except RuntimeError as err:
    print("捕获到异常:", err)
    print("原始异常为：", err.__cause__)
